<style type="text/css">
    .layui-table-body{overflow-x:auto;}
    .layui-table-cell{font-size:12px;}
</style>
<div class="layui-form hisi-search">
    <form action="{:url()}" method="get" id="hisi-table-search">
        <div class="layui-form-item">
            <label class="layui-form-label">关键词</label>
            <div class="layui-input-inline">
                <input type="text" name="keyword" class="layui-input keyword" lay-verify="required" placeholder="订单号"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">分类</label>
            <div class="layui-input-inline">
                <select name="status" class="status">
                    <option value="0">所有订单</option>
                    <option value="1">待支付订单</option>
                    <option value="2">待发货订单</option>
                    <option value="3">待收货订单</option>
                    <option value="4">已完成订单</option>
                    <option value="5">退款订单</option>
                    <option value="6">积分商城订单</option>
                    <option value="7">申请开票订单</option>
                    <option value="8">已开票订单</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item hisi-search-btn">
            <div class="layui-input-inline">
                <button type="submit" class="layui-btn layui-btn-normal layui-icon layui-icon-search" id="data-search-btn">查询</button>
            </div>
        </div>
    </form>
</div>
<table id="dataTable"></table>
<!-- <div style="display: none;">
<table id="dataTable1"></table>
</div> -->
<script type="text/html" id="goodsTpl">
    {{# layui.each(d.goods_info,function(index,item){}}
    <div style="line-height:18px;min-width: 200px;">
            <img src="{{ item.goods_img ? item.goods_img : '__ADMIN_IMG__/avatar.png' }}" width="60" height="60" style="display: block;">
            <br>
            <p class="ml10 fl">产品名：{{ item.goods_name }}</p>
            <p class="ml10 fl">规格：{{ item.goods_spec }}</p>
            <p class="ml10 fl">单价：{{ item.goods_price }}</p>
            <p class="ml10 fl">数量：{{ item.goods_num }}</p>
    </div>
    <br/>
    {{# });}}
</script>

<script type="text/html" id="quanTpl">
    <div style="line-height:18px;min-width: 200px;">
            <p class="ml10 fl">{{ d.quan_name?d.quan_name:'否' }}</p><br>
            <p class="ml10 fl">抵扣价格:{{ d.quan_price>0?d.quan_price:0 }}</p>
    </div>
    <br/>
</script>
<script type="text/html" id="jifenTpl">
    <div style="line-height:18px;min-width: 200px;">
            <p class="ml10 fl">{{ d.jifen?d.jifen:'否' }}</p><br>
            <p class="ml10 fl">抵扣价格:{{ d.jifen_price>0?d.jifen_price:0 }}</p>
    </div>
    <br/>
</script>
<script type="text/html" id="orderStatus">
    <div style="line-height:18px;min-width: 200px;">
            <p class="ml10 fl">
                {{#if (d.pay_status==0){}}
                    <span style="color:red;">待支付</span><br />
                {{#}}}
                {{#if (d.pay_status==1&&d.is_send==0&&d.refund_status==0){}}
                    <span style="color:orange;">待发货</span><br />
                {{#}}}
                {{#if (d.pay_status==1&&d.is_send==1&&d.is_que==0){}}
                    <span style="color:blue;">待收货</span><br />
                {{#}}}
                {{#if (d.pay_status==1&&d.is_send==1&&d.is_que==1){}}
                    <span style="color:green;">已完成</span><br />
                {{#}}}
                {{#if (d.is_refund==1&&d.refund_status==0){}}
                    <span style="color:red;">申请退款</span><br />
                {{#}}}
                {{#if (d.is_refund==1&&d.refund_status==1){}}
                    <span style="color:green;">退款成功</span><br />
                {{#}}}
                
            </p>
    </div>
    <br/>
</script>

<script type="text/html" id="ordersTpl">
    <div style="line-height:18px;min-width: 200px;">
            <!-- <p class="ml10 fl">订单金额：{{ d.order_price }}</p><br /> -->
            <p class="ml10 fl">订单提交时间：{{ d.ctime }}</p><br />
            <p class="ml10 fl">订单类型：{{ d.type }}</p><br />
            <p class="ml10 fl">最终商品成交价：{{ d.order_price }}</p><br />
    </div>
</script>

<script type="text/html" id="userTpl">
    <div style="line-height:18px;min-width: 200px;">
        <p class="ml10 fl">姓名：{{d.name}}</p><br />
        <p class="ml10 fl">电话：{{d.phone}}</p><br />
        <p class="ml10 fl">地址：{{d.province}}{{d.city}}{{d.district}}{{d.address}}</p><br />
        <p class="ml10 fl">批号：{{d.pihao}}</p><br />
        <p class="ml10 fl">包裹数量：{{d.package_num}}</p><br />
        <p class="ml10 fl">包裹重量：{{d.weight}}</p><br />
        {{#if (d.kuaidi_name!=''&&d.kuaidi_num!=''){}}
        <p class="ml10 fl">退换货快递公司：{{d.kuaidi_name}}</p><br />
        <p class="ml10 fl">退换货快递单号：{{d.kuaidi_num}}</p><br />
        {{#}}}
        {{#if (d.is_refund==1){}}
        <p class="ml10 fl">退款原因：{{d.refund_reason}}</p><br />
        {{#}}}
        {{#if (d.waybill_id!=''){}}
        <p class="ml10 fl">发货物流单号：{{d.waybill_id}}</p><br />
        {{#}}}
    </div>
</script>

<script type="text/html" title="操作按钮模板" id="buttonTpl">
    {{#if (d.pay_status==0){}}
    <a href="{:url('changeOrderPrice')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-danger hisi-iframe-pop"  hisi-data="{width: '1000px', height: '600px', title: '修改订单价格'}">修改订单价格</a>
    {{#}}}
    {{#if (d.pay_status==1){}}
    <a href="{:url('editOrder')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-danger hisi-iframe-pop"  hisi-data="{width: '1000px', height: '600px', title: '编辑订单'}">编辑订单</a>
    {{#}}}
    {{#if (d.pay_status==1&&d.is_send==0&&d.refund_status==0&&d.is_refund==0){}}
    <a href="{:url('sendGoods')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-normal hisi-iframe-pop"  hisi-data="{width: '1000px', height: '600px', title: '发货'}">发货</a>
    <a href="{:url('sendGoodsAct')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-danger hisi-iframe-pop"  hisi-data="{width: '1000px', height: '600px', title: '发货通知'}">发货通知</a>
    {{#}}}
    {{#if (d.is_refund==1&&d.refund_status==0&&d.sure_return==1){}}
    <a href="javascript:goRefund({{d.id}})" class="layui-btn layui-btn-xs layui-btn-danger">确认退款</a>
    {{#}}}
    {{#if (d.is_refund==1&&d.refund_status==0){}}
    <a href="javascript:delRefund({{d.id}})" class="layui-btn layui-btn-xs layui-btn-danger">取消退款</a>
    {{#}}}
    {{#if (d.is_refund==1&&d.sure_return==0&&d.refund_status==0){}}
    <a href="javascript:goTui({{d.id}},1)" class="layui-btn layui-btn-xs layui-btn-normal">同意退货</a>
    {{#}}}
    {{#if (d.is_refund==1&&d.sure_return==0&&d.refund_status==0){}}
    <a href="javascript:goTui({{d.id}},-1)" class="layui-btn layui-btn-xs layui-btn-danger">拒绝退货</a>
    {{#}}}
    {{#if (d.fp_title&&d.taxNumber){}}
    <a href="{:url('fapiao')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-normal hisi-iframe-pop"  hisi-data="{width: '1000px', height: '600px', title: '开票信息'}">开票信息</a>
    {{#}}}
    {{#if (d.is_send==1){}}
    <a href="{:url('yundan')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-normal" target="_blank">获取运单</a>
    {{#}}}
    <!-- <a href="{:url('del')}?type=goods&id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-danger j-tr-del">删除</a> -->
</script>
{include file="system@block/layui" /}
<script id="toolbar" type="text/html">
    <!-- <a href="{:url('add')}?type=goods" class="layui-btn layui-btn-normal layui-btn-sm hisi-iframe-pop" hisi-data="{width: '1000px', height: '500px', title: '添加商品'}">&nbsp;添加</a> -->
    <!-- <button  class="layui-btn layui-btn-primary layui-icon layui-icon-play" id="export-id" onclick="javascript:export_data();">&nbsp;导出</button> -->
    <!-- <button type="button" class="layui-btn" id="test1">
        <i class="layui-icon">&#xe67c;</i>导入excel
      </button> -->
</script>
<script type="text/javascript">
    var $ = layui.jquery;
    var table = layui.table;         //表格
	          //表单
	var layer = layui.layer;         //弹层
    var exportData = {};
    var tableObj;
    layui.use(['table','form'], function() {
        var form = layui.form; 
        table.render({
            elem: '#dataTable'
            ,url: '{:url()}' //数据接口
            // ,page:true
            ,page: {
                limit:  20,
                limits: [ 10, 15,  30,  60,  90,  120,  150],
                curr: localStorage. getItem( "spgl_curr")? localStorage. getItem( "spgl_curr"): 1
            }
            // ,where:{
            //     status:localStorage. getItem( "status")? localStorage. getItem( "status"):0,
            //     keyword:localStorage. getItem( "keyword")? localStorage. getItem( "keyword"):'',
            // }
            ,skin: 'row'
            ,even: true
            ,text: {
                none : '暂无相关数据'
            }
            // ,toolbar: "#toolbar"
            // ,title:'用户订单列表'
            // ,totalrow:true
            // ,defaultToolbar: ['filter']
            ,cols: [[ //表头
                {field: 'id', title: 'ID',width:20}
                ,{field: 'orders_id', title: '订单号'}
                ,{field: 'nickname', title: '买家名称'}
                ,{title: '商品详情', templet: '#goodsTpl',width:350}
                ,{field: 'pay_time', title: '支付时间'}
                ,{title: '优惠券',templet:'#quanTpl'}
                ,{ title: '积分',templet:'#jifenTpl'}
                // ,{field: 'jifen_price', title: '积分抵扣金额'}
                ,{title:'订单信息',templet:'#ordersTpl',width:250}
                ,{field: 'waybill_id',title: '物流单号'}
                ,{title: '订单状态',templet:'#orderStatus'}
                ,{title: '用户信息',templet:'#userTpl',width:200}
                ,{title: '操作', width: 250, templet: '#buttonTpl'}
            ]]
            ,enabledCurrCookie: true
            ,parseData: function(res) {
                // console.log('res:');
                // console.log(res.data);
                // exportData = res.data;
                // return {
                //     code: res.code,
                //     msg: res.msg,
                //     count: res.data.count,
                //     data: res.data
                // }
            }
            ,done: function(res,curr,count){
                if (typeof(layui.global.addTableTool) !== 'undefined') {
                    layui.global.addTableTool();
                }
                // console. log( res,  curr,  count);
                // localStorage. setItem( "spgl_curr", curr); //存储页码

                // if(localStorage.getItem( "status")){
                //     $(".status").val(localStorage.getItem( "status"));
                // }
                // if(localStorage.getItem( "keyword")){
                //     $(".keyword").val(localStorage.getItem( "keyword"));
                // }
            }
        });

    });

    $("#data-search-btn").click(function(){
        var keyword = $(".keyword").val();
        var status = $(".status").val();
        localStorage. setItem( "keyword", keyword);
        localStorage. setItem( "status", status);
    })
    

    function export_data(){
        // layer.alert('hello');
        // console.log(exportData);
        table.exportFile('id', exportData, 'xls');
    }
    //表格导出
	// $("#export-id").click(function(){
    //     layer.alert('hello');
	// 	// table.exportFile(tableObj.config.id, exportData, 'xls');
	// })

    layui.use('upload', function(){
        var upload = layui.upload; //得到 upload 对象
        //创建一个上传组件
        upload.render({
        elem: '#test1'
        ,url: '{:url("goods_import")}'
        ,method:'post'
        ,done: function(res){ //上传后的回调
            // console.log(res);
            if(res.status=='success'){
                layer.msg('导入成功');
                window.location.reload();
            }
            else{
                layer.msg(res.msg);
            }
        } 
        ,accept: 'file' //允许上传的文件类型
        //,size: 50 //最大允许上传的文件大小
        //,……
        })
    });

    

    function goRefund(id){
        // layer.alert(id);
        $.ajax({
            url:"{:url('refund')}",
            data:{id:id},
            dataType:"json", //接口json格式
            success:function(data){
                layer.alert(data.msg);
                window.location.reload();
                // layer.alert(JSON.stringify(data), {
                //     title: data
                // });
            },
            error:function(data){
                layer.alert(data.msg);
                // layer.alert(JSON.stringify(data), {
                //     title: data
                // });
            }
        });
    }

    function delRefund(id){
        $.ajax({
            url:"{:url('delRefund')}",
            data:{id:id},
            dataType:"json", //接口json格式
            success:function(data){
                layer.alert(data.msg);
                window.location.reload();
                // layer.alert(JSON.stringify(data), {
                //     title: data
                // });
            },
            error:function(data){
                layer.alert(data.msg);
                // layer.alert(JSON.stringify(data), {
                //     title: data
                // });
            }
        });
    }

    function goTui(id,type){
        $.ajax({
            url:"{:url('sureReturn')}",
            data:{id:id,type:type},
            dataType:"json", //接口json格式
            success:function(data){
                layer.alert(data.msg);
                window.location.reload();
                // layer.alert(JSON.stringify(data), {
                //     title: data
                // });
            },
            error:function(data){
                layer.alert(data.msg);
                // layer.alert(JSON.stringify(data), {
                //     title: data
                // });
            }
        });
    }

    function goods_export(){
        
    }
</script>